
var api = require('../../../utils/api.js')
var $ = require('../../../utils/util.js')
var regeneratorRuntime = require('../../../utils/runtime.js')
var app = getApp()

Page({
  data: {
    id: 0, 
    info: {},
    result: '',  // 巡检结果
    imgUrl: api.imageUrl, // 图片url
    "image1" : "",  // 上传'图片1',
    "image2" : "",  // 上传'图片2',
    "image3" : "",  // 上传'图片3',
  },
  onLoad: function (options) {
    if ('id' in options) {
      this.setData({
        id: options.id,
        ticket_num:options.ticket_num
      })
    }
    this.getInfo()
  },
  onShow: function () {

  },
  getInfo() { // 获取详情信息
    var params = {
      id: this.data.id,
      ticket_num:this.data.ticket_num
    }
    api.$get(api.pollingManage.info, params).then((res) => {
      this.setData({
        info: res.data,
        image1:res.data.info.image1,
        image2:res.data.info.image2,
        image3:res.data.info.image3,
      })
    })
  },
  upPicsHandle(e) { // ##图片组件传出来的数据##
    var { pics, key } = e.detail
    console.log(pics, key)
    this.setData({
      [key]: pics.length>0?pics[0]:[]
    })
   
  },
  callHandle(e) {
    var { phone } = $.detail(e)
    $.call(phone)
  },
  updateInfoHandle() { // 执行巡检任务
    if ($.isNull(this.data.result)) {
      $.toast('请输入巡检结果')
    }else if($.isNull(this.data.image1) || $.isNull(this.data.image2) ||$.isNull(this.data.image3)){
      $.toast('请上传3张巡检图片');
    }
     else {
      var params = {
        ticket_num: this.data.ticket_num,
        result: this.data.result,
        image1:this.data.image1,
        image2:this.data.image2,
        image3:this.data.image3,
        status: '1'
      }
      api.$post(api.pollingManage.updateInfo, params).then((res) => {
        $.toast('提交成功')
        setTimeout(() => {
          $.linkurl('/pages/pollingManage/pollingManageIndex/pollingManageIndex')
        },1500)
      })
    }
    
  },

  //##input 输入##
  input_handle(e) {
    this.setData({
      [e.currentTarget.dataset.key]: e.detail
    })
  },
  //##input 输入##

  toDefectRecordHandle(e) { // 去缺陷记录
    var { equipment, type } = $.detail(e)  
    $.linkurl(`/pages/pollingManage/pollingManageDefectRecord/pollingManageDefectRecord?company=${this.data.info.info.company_name}&factory=${this.data.info.info.factory_name}&ticket_num=${this.data.info.info.ticket_num}&currentTab=${type}`)
  },

  toPollingManageInspectionRecord() { // 去继续巡检  
    if(this.data.info.info.equip==null) 
    $.linkurl(`/pages/pollingManage/pollingManageInspectionRecord/pollingManageInspectionRecord?ticket_num=${this.data.info.info.ticket_num}&company=${this.data.info.info.company_name}&factory=${this.data.info.info.factory_name}&id=${this.data.id}`)
    else
    $.linkurl(`/pages/pollingManage/pollingManageInspectionRecord/pollingManageInspectionRecord?ticket_num=${this.data.info.info.ticket_num}&company=${this.data.info.info.company_name}&factory=${this.data.info.info.factory_name}&id=${this.data.id}&equip=${this.data.info.info.equip}`)
},


})